using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using ManagedSail;

namespace DxVirtualFrameBuffer
{
    public partial class ControlForm : Form
    {
        private MainForm mainForm = null;
        private int resolution = 512;

        public ControlForm()
        {
            InitializeComponent();
        }

        public void SetMainForm(MainForm form)
        {
            mainForm = form;
        }

        private void OnResolutionSelected(object sender, EventArgs e)
        {
            RadioButton rb = sender as RadioButton;
            if (rb != null)
                mainForm.SetVFBResolution(resolution = Int32.Parse(rb.Tag.ToString()));
        }

        public void SetGpuToCpuAvgCopyTime(double ms)
        {
            avgMemCopyTimeLabel.Text = "GPU to CPU copy time: " + ms.ToString() + "ms";
        }

        private Sail sail = null;

        public Sail Sail
        {
            get { return sail; }
        }

        public bool SailMode
        {
            get { return sail != null; }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.Filter = "SAIL Configuration (*.conf)|*.conf";

            if(ofd.ShowDialog() == DialogResult.OK)
            {
                try
                {
                /*    SailConfig sailConfig = new SailConfig();
                    sailConfig.Init(ofd.FileName);

                    SageRectangle rect = new SageRectangle(0, 0, resolution, resolution);
                    sailConfig.imageMap = rect;
                    sailConfig.winX = 0;
                    sailConfig.winX = 0;
                    sailConfig.winWidth = resolution;
                    sailConfig.winHeight = resolution;
                    sailConfig.resX = resolution;
                    sailConfig.resY = resolution;
                    */
                    sail = new Sail();
                    sail.Init(ofd.FileName,resolution,resolution);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Cannot init SAIL", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
    }
}